function pixTrace(himg)
% pixTrace     Get pixels' traces by mouse-pointing
% himg: an image handle
%
% Editing:
% gs feb 2005
% gs april 2005 -- modified for mapAnalysis3p0
% gs may 2006 - %GS20060524 - modified for ephus compatibility; flipud's added
% ------------------------------------------------- 

% % stuff a map sequence into the image's UserData
% set(himg, 'UserData', data);

% set the callback to the subfunction below
set(himg, 'ButtonDownFcn', @pickByMouse);

% ----SUBFUNCTION---------------------------------- 
function pickByMouse(src, eventdata)

% retrieve the map pattern and map data
handles = get(gcf, 'UserData');
M = flipud(handles.data.map.mapActive.mapPattern);  % GS200605024
% Note: this line was modified for mapAnalysis3p0

% get the XY value of the selected point
XY = get(gca, 'CurrentPoint');
X = XY(1,1);
Y = XY(1,2);

% calculate array indices: 
% column:
xdata = get(gco, 'XData');
numCols = size(M,2);
pixelSideX = (xdata(2) - xdata(1))/(numCols - 1);
fullSideX = [xdata(1)-pixelSideX/2 xdata(2)+pixelSideX/2];
Xfraction = (X - fullSideX(1)) / (fullSideX(2) - fullSideX(1));
colInd = ceil(Xfraction * numCols);
% row:
ydata = get(gco, 'YData');
numRows = size(M,1);
pixelSideY = (ydata(2) - ydata(1))/(numRows - 1);
fullSideY = [ydata(1)-pixelSideY/2 ydata(2)+pixelSideY/2];
Yfraction = (Y - fullSideY(1)) / (fullSideY(2) - fullSideY(1));
% Yfraction = (Y - fullSideY(2)) / (fullSideY(1) - fullSideY(2));
rowInd = ceil(Yfraction * numRows);

% index into the map pattern to get the trace number
traceNumber = M(rowInd, colInd);
% disp(num2str(traceNumber));

% update the current trace
traceAdvancer3p0(traceNumber);